/**
 * Created by gongxun on 17/1/11.
 */


var KwxStoreLayer = KwxBaseLayer.extend({
    Panel_center : null,
    ctor: function () {
        this._super();
        this.loadCocostudio("res/ccs/KwxStoreLayer.json");
        mo.gameHelper.fixIosText(this.ccsNode);
        this.Panel_center = mo.seekWidgetByName(this.ccsNode, "Panel_center");


        //关闭
        mo.seekWidgetByName(this.ccsNode, "Button_close").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEndMenuClose(type)) {
                this.closeAction(this.Panel_center);
            }
        }, this);

        //关闭
        mo.seekWidgetByName(this.ccsNode, "Panel_touch").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEndMenuClose(type)) {
                this.closeAction(this.Panel_center);
            }
        }, this);
    },

    onEnter : function(){
        this._super();

        this.showAction(this.Panel_center);

        var payIds = [];
        if (mo.gameHelper.projectCode == 0){
            payIds = [
                "com.mjgame.roomcard0",
                "com.mjgame.roomcard1",
                "com.mjgame.qxkwxRoomcard2"
            ];
        }else if (mo.gameHelper.projectCode == 1){
            payIds = [
                "lefan.mongsanyo.roomcard0",
                "lefan.mongsanyo.roomcard1",
                "lefan.mongsanyo.roomcard2"
            ];
        }else if (mo.gameHelper.projectCode == 2){
            payIds = [
                "com.16youxi.nbroomcard0",
                "com.16youxi.nbroomcard1"
            ];
        }

        for (var i = 0; i < payIds.length; i++){
            var Button_pay = mo.seekWidgetByName(this.ccsNode, "Button_pay" + i);
            Button_pay.setTag(i);
            Button_pay.addTouchEventListener(function(sender, type){
                if (mo.gameHelper.getIsTouchEnd(type)) {
                    var index = sender.getTag();

                    // mo.gameMsgManager.sendAddPoint(10);
                    // return;
                    var that = this;
                    mo.nativeHelper.onAppStorePay(payIds[index], function(iosid){
                        cc.log(iosid);
                        var addnum = 0;
                        if (iosid == payIds[0]){
                            addnum = 1;
                        }else if (iosid == payIds[1]){
                            addnum = 10;
                        }else if (iosid == payIds[2]){
                            addnum = 20;
                        }
                        mo.gameMsgManager.sendAddPoint(addnum);
                        that.closeAction(that.Panel_center);
                    });
                }
            }, this);
        }
    }
});